package enums;

import java.text.SimpleDateFormat;
import java.util.Locale;

public class Enum {
	public static void main(String[] args) {
		System.out.println("name(): "+Test.JAN.name());
		System.out.println("toString(): "+Test.JAN.toString());
		System.out.println("valueOf(): "+Test.valueOf("JAN"));
		
		iterateEnum();
		
		ordinalEnum();
		
		Country.GER.getCountryName(); // DEU
		Country.GER.getCountryNameSwitch(); // Germany
		
		
		Country2.GER.getCountryName(); // Germany
		
		System.out.println(WeekInternational.TUESDAY); // Dienstag
		
		System.out.println(GameCurrency.TESTDOLLAR.convertTo(GameCurrency.EURO, 100)); // 200
	}
	
	
	/**
	 * iterate over enum
	 */
	public static void iterateEnum(){
		
		// print constants variant 1
		for(Test t: Test.values()){
			System.out.println(t);
		}
		
		// print constants variant 2
		for(Test t: Test.class.getEnumConstants()){
			System.out.println(t);
		}
		
	}
	
	
	public static void ordinalEnum(){
		// ordinal
		System.out.println(Test.MAR.ordinal()); // 2
		System.out.println(Test.JAN.compareTo(Test.FEB)); // -1
	}
	
	
	/**
	 * Simple enum
	 *
	 */
	public enum Test
	{
		 JAN, FEB, MAR;
	}
	
	/**
	 *	Enum with own methods 
	 *
	 */
	public enum Country
	{
		GER, USA, CHINA;
		
		public void getCountryName(){
			if(this == GER) System.out.println(Locale.GERMANY.getISO3Country());
			else if(this==USA) System.out.println(Locale.US.getISO3Country());
			else System.out.println(Locale.CHINA.getISO3Country());
		}
		
		public void getCountryNameSwitch(){
			switch(this){
				case GER: System.out.println("Germany"); break;
				case USA: System.out.println("USA"); break;
				case CHINA: System.out.println("China"); break;
			}
		}
	}
	
	/**
	 * Enum with constructor 
	 *
	 */
	public enum Country2{
		GER("Germany"), USA("USA"), CHINA("China");
		
		private String name;
		
		private Country2(String name){
			this.name = name;
		}
		public void getCountryName(){
			System.out.println(name);
		}
	}
	
	/**
	 * Override methods in enum
	 *
	 */
	public enum WeekInternational{
		SUNDAY, MONDAY, TUESDAY, WEDNESDAY;
		
		@Override
		public String toString() {
			return new SimpleDateFormat().getDateFormatSymbols().getWeekdays()[ordinal()+1];
		};
	}
	
	
	/**
	 * Abstract method in enum 
	 *
	 */
	public enum GameCurrency{
		EURO(){
			@Override
			double convertTo(GameCurrency targetCurrency, double value){
				return targetCurrency == EURO ? value : value / 2 ;
			}
		},
		TESTDOLLAR(){

			@Override
			double convertTo(GameCurrency targetCurrency, double value) {
				return targetCurrency == TESTDOLLAR ? value : value * 2;
			}
			
		};
		
		abstract double convertTo(GameCurrency targetCurrency, double value);
	}
}
